package com.common.jms;

import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.beans.factory.annotation.Autowired;

import com.common.email.MimeMailService;

/**
 * 消息的异步被动接收者.
 * 
 * 使用Spring的MessageListenerContainer侦听消息并调用本Listener进行处理.
 * 
 * @author calvin
 *
 */
public class NotifyMessageListener implements MessageListener {

	@Autowired
	private MimeMailService mailService;

	//private SimpleMailService mailService;

	public void onMessage(Message message) {
		try {
			MapMessage mapMessage = (MapMessage) message;
			mailService.sendNotificationMail(mapMessage.getString("username"));
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

	public void setMailService(MimeMailService mailService) {
		this.mailService = mailService;
	}
}
